import 'package:flutter/material.dart';
import 'package:fluro/fluro.dart';

import '../page/home_page.dart';
import '../helpers/color_helper.dart';
import '../page/simple_page.dart';
import '../page/index_page.dart';

import '../page/drawer/people_page.dart';
import '../page/drawer/favourite_page.dart';
import '../page/provider/counter_page.dart';
import '../page/quiz/quiz_page.dart';
import '../page/flu_widget/index.dart';
import '../page/native_component/native_page.dart';
import '../page/native_component/native_battery.dart';


var rootHandler = Handler(
  handlerFunc: (BuildContext? context, Map<String, List<String>> params) {
    return HomePage();
  }
);

var routerIndexHandler = Handler(
  handlerFunc: (BuildContext? context, Map<String, List<String>> params) {
    return IndexPage();
  }
);

var demoRouterHandler = Handler(
  handlerFunc: (BuildContext? context, Map<String, List<String>> params) {
    String? message = params["message"]?.first;
    String? colorHex = params["color_hex"]?.first;
    String? result = params["result"]?.first;
    Color color = const Color(0xFFFFFFFF);
    if (colorHex != null && colorHex.length > 0) {
      color = Color(ColorHelpers.fromHexString(colorHex));
    }
    return SimplePage(
      message: message ?? 'Testing', 
      color: color, 
      result: result
    );
  }
);

var demoFunctionHandler = Handler(
  type: HandlerType.function,
  handlerFunc: (BuildContext? context, Map<String, List<String>> params) {
    String? message = params["message"]?.first;
    showDialog(
      context: context!, 
      builder: (context) {
        return AlertDialog(
          title: const Text(
            "Hey Hey!",
            style: TextStyle(
              color: Color(0xFF00D6F7),
              fontFamily: "Lazer84",
              fontSize: 22.0,
            ),
          ),
          content: Text("$message"),
          actions: [
            Padding(
              padding: const EdgeInsets.only(bottom: 8.0, right: 8.0),
              child: TextButton(
                onPressed: () {
                  Navigator.of(context).pop(true);
                },
                child: const Text('OK'),
              ),
            )
          ],
        );
      }
    );
  }
);

var deepLinkHandler = Handler(
  handlerFunc: (BuildContext? context, Map<String, List<String>> params) {
    String? colorHex = params["result"]?.first;
    String? result = params["result"]?.first;
    Color color = const Color(0xFFFFFFFF);
    if (colorHex != null && colorHex.length > 0) {
      color = Color(ColorHelpers.fromHexString(colorHex));
    }
    return SimplePage(
      message: "DEEEEEEP LINK!!!",
      color: color,
      result: result,
    );
  }
);

var favouriteHandler = Handler(
  handlerFunc: (BuildContext? context, Map<String, List<String>> params) {
    return const FavouritePage();
  }
);

var peoplePageHandler = Handler(
  handlerFunc: (BuildContext? context, Map<String, List<String>> params) {
    return const PeoplePage();
  }
);

var counterPageHandler = Handler(
  handlerFunc: (BuildContext? context, Map<String, List<String>> params) {
    return const CounterPage();
  }
);

var quizPageHandler = Handler(
  handlerFunc: (BuildContext? context, Map<String, List<String>> params) {
    return const QuizPage();
  }
);

var widgetListHandler = Handler(
  handlerFunc: (BuildContext? context, Map<String, List<String>> params) {
    return NativeWidgetList();
  }
);

var nativeViewHandler = Handler(
  handlerFunc: (BuildContext? context, Map<String, List<String>> params) {
    return NativePage();
  }
);

var nativeBatteryHandler = Handler(
  handlerFunc: (BuildContext? context, Map<String, List<String>> params) {
    return NativeBattery();
  }
);
